package com.lanqiao.gxnushop.controller;

import com.lanqiao.gxnushop.entity.Orders;
import com.lanqiao.gxnushop.entity.Products;
import com.lanqiao.gxnushop.service.OrdersService;
import com.lanqiao.gxnushop.service.ProductsService;
import com.lanqiao.gxnushop.valueObject.OrderDetails;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.log4j.Log4j;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Log4j
@Tag(name="OrdersController",description="订单服务")
@RestController
public class OrdersController {
    @Autowired
    private OrdersService ordersService;
    @Autowired
    private ProductsService productsService;

    @PostMapping("/orders")
    @Operation(summary="批量添加订单, 如果有任一商品库存不足则返回false，成功添加所有订单则返回true")
    @Parameter(name = "ordersList", description = "包含多个订单的列表，每个订单包含storeId(商铺Id), productId(商品Id), buyerId(买家Id), addressId(地址Id), quantity(数量), totalAmount(总金额), state(订单状态), zcsj(已自动导入)")
    public boolean addOrders(@RequestBody ArrayList<Orders> ordersList) {
        return ordersService.addOrdersBatch(ordersList);
    }

    @DeleteMapping("/orders/{ordersId}")
    @Operation(summary="根据订单Id删除订单")
    @Parameter(name = "ordersId",description = "订单(ordersId)")
    public boolean deleteOrders(@PathVariable String ordersId)
    {
        return ordersService.delete(ordersId);
    }

    @GetMapping("/orders/selectBuyerAll/{buyerId}")
    @Operation(summary="根据买家buyerId查询所有订单")
    @Parameter(name = "buyerId",description = "买家buyerId")
    public ArrayList<OrderDetails> findByBuyerId(@PathVariable String buyerId)
    {
        return ordersService.findByBuyerId(buyerId);
    }

    @GetMapping("/orders/selectOne/{ordersId}")
    @Operation(summary="根据订单id查询指定订单")
    @Parameter(name = "ordersId",description = "订单ordersId")
    public Orders findById(@PathVariable String ordersId)
    {
        return ordersService.findById(ordersId);
    }

    @GetMapping("/orders/selectStore/{storeId}")
    @Operation(summary="根据店铺id查询所有订单")
    @Parameter(name = "storeId",description = "店铺storeId")
    public ArrayList<Orders> findByStoreId(@PathVariable String storeId)
    {
        return ordersService.findByStoreId(storeId);
    }

    @PutMapping("/orders")
    @Operation(summary="更新订单")
    @Parameter(name = "orders",description = "quantity(数量),totalAmount(总金额),state(订单状态)")
    public boolean updateOrders(Orders orders)
    {
        return ordersService.update(orders);
    }
    /*@GetMapping("/orders/{ordersId}")
    @Operation(summary="根据订单id查询商品")
    @Parameter(name = "ordersId",description = "订单id")
    public Products findProductByOrdersId(@PathVariable String ordersId)
    {
        return ordersService.findProductByOrdersId(ordersId);
    }

    @GetMapping("/orders/{ordersId}")
    @Operation(summary="根据订单id查询买家")
    @Parameter(name = "ordersId",description = "订单id")
    public Orders findBuyerByOrdersId(@PathVariable String ordersId)
    {
        return ordersService.findBuyerByOrdersId(ordersId);
    }

    @GetMapping("/orders/{ordersId}")
    @Operation(summary="根据订单id查询店铺")
    @Parameter(name = "ordersId",description = "订单id")
    public Products findStoreByOrdersId(@PathVariable String ordersId)
    {
        return ordersService.findStoreByOrdersId(ordersId);
    }*/

}
